//
//  MyTakeOrderDetailGoodListVC.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2021/1/27.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "MyTakeOrderDetailGoodListVC.h"
#import "MyTakeOrderDetailGoodListCell.h"
#import "MyTakeOrderDetailGoodStatisticsView.h"

@interface MyTakeOrderDetailGoodListVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation MyTakeOrderDetailGoodListVC

-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH - NaviHeight - BottomHeight) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = Color_backgroundColor;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"货物清单";
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
    [btn setTitle:@"统计" forState:0];
    [btn setTitleColor:Color_ThemeColor forState:0];
    btn.backgroundColor = HexColorA(0x3D68EB, 0.1);
    btn.layer.cornerRadius = 15;
    btn.titleLabel.font = BoldFontOfSize(14);
    [btn addTarget:self action:@selector(statisticsClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [self.view addSubview:self.tableView];
}

- (void)statisticsClick {
    MyTakeOrderDetailGoodStatisticsView *view = [MyTakeOrderDetailGoodStatisticsView new];
    view.type = self.model.goods_trans_type;
    view.jnum = self.model.goodsJnum;
    view.num = self.model.goodsNum;
    view.weight = [self.model.allWeight floatValue] ? [NSString stringWithFormat:@"%@KG",self.model.allWeight] : @"--KG";
    view.volume = [self.model.allVolume floatValue] ? [NSString stringWithFormat:@"%@m³",self.model.allVolume] : @"--m³";
    [view showInView:MAIN_WINDOW];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.model.goods_list.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTakeOrderDetailGoodListCell *cell = [MyTakeOrderDetailGoodListCell MyTakeOrderDetailGoodListCellWithTableView:tableView];
    MyTakeOrderDetailGoodModel *model = self.model.goods_list[indexPath.section];
    cell.model = model;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTakeOrderDetailGoodListCell *cell = [MyTakeOrderDetailGoodListCell MyTakeOrderDetailGoodListCellWithTableView:tableView];
    MyTakeOrderDetailGoodModel *model = self.model.goods_list[indexPath.section];
    cell.model = model;
    return cell.height;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 10)];
        view.backgroundColor = Color_backgroundColor;
        return view;
    }
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 10;
    }
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 10)];
    view.backgroundColor = Color_backgroundColor;
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

@end
